// 页面加载时从本地存储获取计数
document.addEventListener('DOMContentLoaded', function() {
    // 获取王中晖的计数
    let count1 = localStorage.getItem('wangzhonghui_count');
    if (count1 === null) {
        count1 = 0;
        localStorage.setItem('wangzhonghui_count', count1);
    }
    document.getElementById('count1').textContent = count1;
    
    // 获取王亮的计数
    let count2 = localStorage.getItem('wangliang_count');
    if (count2 === null) {
        count2 = 0;
        localStorage.setItem('wangliang_count', count2);
    }
    document.getElementById('count2').textContent = count2;
});

// 增加计数
function incrementCount(player) {
    let countElement, storageKey;
    
    if (player === 1) {
        countElement = document.getElementById('count1');
        storageKey = 'wangzhonghui_count';
    } else {
        countElement = document.getElementById('count2');
        storageKey = 'wangliang_count';
    }
    
    let currentCount = parseInt(countElement.textContent);
    currentCount++;
    countElement.textContent = currentCount;
    
    // 保存到本地存储
    localStorage.setItem(storageKey, currentCount);
    
    // 添加点击动画效果
    countElement.classList.add('pulse');
    setTimeout(() => {
        countElement.classList.remove('pulse');
    }, 300);
}

// 重置计数
function resetCounts() {
    if (confirm('确定要重置所有计数吗？')) {
        localStorage.setItem('wangzhonghui_count', 0);
        localStorage.setItem('wangliang_count', 0);
        document.getElementById('count1').textContent = 0;
        document.getElementById('count2').textContent = 0;
    }
}

// 添加CSS动画
const style = document.createElement('style');
style.textContent = `
    .pulse {
        animation: pulse 0.3s;
    }
    
    @keyframes pulse {
        0% { transform: scale(1); }
        50% { transform: scale(1.2); }
        100% { transform: scale(1); }
    }
`;
document.head.appendChild(style);